package com.company.servicename.amqp;

import org.apache.log4j.Logger;
import org.springframework.amqp.core.Message;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

/**
 * @author fangsong.zhang
 * @date 2019年9月25日
 * Copyright zfs
 * 类说明:监听消息
 */
@Component
public class Receiver {

    private final static Logger logger = Logger.getLogger(Receiver.class);

    /**
     * 接收消息
     *
     * @param message 消息
     */
    @RabbitListener(queues = "queue name")
    public void someName(Message message) {
        try {
            String msgContent = new String(message.getBody(), "utf-8");
            logger.debug(msgContent + "开始处理");
        } catch (Exception e) {
            logger.error(message.toString() + "处理异常");
        }
    }
}
